package com.xinqi.modules.sys.log.factory;

import com.xinqi.common.base.error.CommonErrors;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.sys.log.client.OperatorLogClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 操作日志记录降级处理
 *
 * @author: yyzhen
 * @date: 2023/08/23
 */
@Slf4j
@Component
public class OperatorLogFallbackFactory implements FallbackFactory<OperatorLogClient> {

    @Override
    public OperatorLogClient create(Throwable throwable) {
        log.error("日志服务调用失败:{}", throwable.getMessage());
        return new OperatorLogClient() {

            @Override
            public R<Long> insert(Map<String, Object> log) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }
        };
    }
}
